package com.lczc.soa.service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.lczc.soa.domain.Admin;
import com.lczc.soa.domain.AdminExample;
import com.lczc.soa.domain.SearchAdminResponse;

import com.lczc.soa.mapper.AdminMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AdminServiceImpl implements AdminService {

    @Autowired
    private AdminMapper adminMapper;


    @Override
    public Admin findAdminByName(String adminName) {
        return adminMapper.selectByName(adminName);
    }

    @Override
    public SearchAdminResponse findAllAdmin(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Admin> admins = adminMapper.selectByExample(new AdminExample());
        return new SearchAdminResponse(((Page)admins).getTotal(),admins);
    }

    @Override
    public SearchAdminResponse findAdminLikeName(String keywords, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Admin> admins =adminMapper.selectByLikeName(keywords);
        return new SearchAdminResponse(((Page)admins).getTotal(),admins);
    }

    @Override
    public int deleteAdmin(String id) {
        return adminMapper.deleteByPrimaryKey(id);
    }

}
